<?php

class Model_Category extends Model {
    
    private $table = "categories";
    
    public function getMainCategories()
    {
        $sql = "SELECT * FROM  {$this->table} WHERE ISNULL(parent_id)";
        return $this->db->query($sql)->fetchAll();
    }
    
    public function getCategoriesForProductSelect()
    {
        $sql = "SELECT id, name FROM {$this->table} WHERE ISNULL(parent_id)";
        $categories = $this->db->query($sql)->fetchAll();
        
        $result = array();
        foreach ($categories as $category) 
        {
            $result[$category['id']] = $category['name'];
        }
        
        return $result;
    }
}
